package com.atguigu.lease.web.admin.service.impl;

import com.atguigu.lease.model.entity.*;
import com.atguigu.lease.web.admin.mapper.ApartmentInfoMapper;
import com.atguigu.lease.web.admin.mapper.LeaseAgreementMapper;
import com.atguigu.lease.web.admin.service.*;
import com.atguigu.lease.web.admin.vo.agreement.AgreementQueryVo;
import com.atguigu.lease.web.admin.vo.agreement.AgreementVo;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.swagger.v3.oas.annotations.media.Schema;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author liubo
 * @description 针对表【lease_agreement(租约信息表)】的数据库操作Service实现
 * @createDate 2023-07-24 15:48:00
 */
@Service
public class LeaseAgreementServiceImpl extends ServiceImpl<LeaseAgreementMapper, LeaseAgreement>
        implements LeaseAgreementService {

    @Autowired
    private ApartmentInfoService apartmentInfoService;

    @Autowired
    private RoomInfoService roomInfoService;

    @Autowired
    private PaymentTypeService paymentTypeService;

    @Autowired
    private LeaseTermService leaseTermService;

    @Override
    public IPage<AgreementVo> pageAgreementVo(Page<AgreementVo> page, AgreementQueryVo queryVo) {
        return baseMapper.pageAgreementVo(page,queryVo);
    }

    @Override
    public AgreementVo getAgreementVoById(Long id) {
        AgreementVo agreementVo = new AgreementVo();
        LeaseAgreement leaseAgreement = getById(id);
        BeanUtils.copyProperties(leaseAgreement, agreementVo);

        // 查询签约公寓信息
        agreementVo.setApartmentInfo(apartmentInfoService.getById(agreementVo.getApartmentId()));
        // 查询签约房间信息
        agreementVo.setRoomInfo(roomInfoService.getById(agreementVo.getRoomId()));
        // 查询支付方式
        agreementVo.setPaymentType(paymentTypeService.getById(agreementVo.getPaymentTypeId()));
        // 查询租期
        agreementVo.setLeaseTerm(leaseTermService.getById(agreementVo.getLeaseTermId()));

        return agreementVo;
    }
}




